<div class="yiiForm">

<?php $this->widget('application.components.RequiredMessage'); ?>

<?php
echo CHtml::beginForm();

echo CHtml::activeHiddenField($owner, 'id');
echo CHtml::activeHiddenField($owner, 'adviser_initials');

?>

<h2><?php echo Yii::t('project', 'Owner detail'); ?></h2>

<?php echo CHtml::errorSummary($owner); ?>

<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'first_name'); ?>
<?php echo CHtml::activeTextField($owner, 'first_name');?>
</div>

<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'last_name'); ?>
<?php echo CHtml::activeTextField($owner, 'last_name');?>
</div>

<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'gender'); ?>
<table border="0" cellspacing="0" cellpadding="0" width="50%">
<tr>
	<td>
		<?php echo CHtml::activeRadioButtonList($owner,'gender',Constants::genders(), array('separator' => "</td><td>")); ?>
	</td>
</tr>
</table>
</div>


<div class="simple">
<?php 

	$opts = array();
	$attribute = birth_date;
	CHtml::resolveNameId($owner, $attribute, $opts);
	echo CHtml::activeLabelEx($owner,'birth_date'); 
	$this->widget('zii.widgets.jui.CJuiDatePicker', array (
		//'id'=>'param_value_'.$i,
		'name' => $opts['name'],
		'attribute' => "birth_date",
		'value' => ($owner->birth_date != null ? $owner->birth_date->format(Constants::DISPLAY_DATE_FORMAT) : DateUtils::today()->format(Constants::DISPLAY_DATE_FORMAT)),
		// additional javascript options for the date picker plugin
		'options' => Constants::$JuiDatePickerOptions
	));
?> (dd/mm/yyyy)
</div>

<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'address1'); ?>
<?php echo CHtml::activeTextField($owner,'address1',array('size'=>60,'maxlength'=>255)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'address2'); ?>
<?php echo CHtml::activeTextField($owner,'address2',array('size'=>60,'maxlength'=>255)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'address3'); ?>
<?php echo CHtml::activeTextField($owner,'address3',array('size'=>60,'maxlength'=>255)); ?>
</div>

<div class="simple">
<?php 

$htmlOptions = array();
$htmlOptions['required']=$owner->isAttributeRequired('city_id');
$htmlOptions['size']=40;
if($owner->hasErrors($attribute))
	$htmlOptions['class']=CHtml::$errorCss;

$n = 'city_id';
$opts = array();
CHtml::resolveNameID($owner,$n,$opts);
echo CHtml::activeLabelEx($owner,'city_id'); 

$this->widget('CAutoComplete', array (
	'name' => 'city_name',
	'url' => array ('project/findCity'),
	'max' => 10, //specifies the max number of items to display
	'minChars' => 2,
	'delay' => 500, //number of milliseconds before lookup occurs
	'matchCase' => false, //match case when performing a lookup?
	'htmlOptions' => $htmlOptions,
	'value' => $_POST['city_name'],
	'methodChain' => ".result(function(event,item){ \n\n\$(\"#" . $opts['id'] . "\").val(item[1]);\n\n})",
));

$p = 'city_id';
$options = array ();
CHtml::resolveNameID($owner, $p, $options);

echo CHtml::activeHiddenField($owner, $p);
?>
</div>

<div class="simple">
<?php
if ($cities != null) {
	array_unshift($cities, new City());
	echo CHtml::label("&nbsp;", "tt");
	echo CHtml::dropDownList('city_id', '', CHtml::listData($cities, 'id', 'label'));
}
?>


</div>

<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'phone_number'); ?>
<?php echo CHtml::activeTextField($owner,'phone_number',array('size'=>60,'maxlength'=>255)); ?>
</div>

<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'email'); ?>
<?php echo CHtml::activeTextField($owner,'email',array('size'=>60,'maxlength'=>255)); ?>
</div>

<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'referent'); ?>
<?php echo CHtml::activeTextField($owner,'referent',array('size'=>60,'maxlength'=>255)); ?>
</div>

<div class="simple">
<?php echo CHtml::activeLabelEx($owner,'service_id'); ?>
<?php echo CHtml::activeDropDownList($owner,'service_id', CHtml::listData(Service::model()->findAll(), 'id', 'label'), array('style' => 'width:250px;')); ?>
</div>

<?php
$param = Yii::app()->parameter->getParametersArray('OWNER_SPEC');
$p = array();
foreach ($param as $id=>$arr){
	$p[$param[$id]['FLDNAM']] = $param[$id]['FLDLBL'] ;
}

foreach ($specificData as $id=>$specificDatum) {
	$name = '['.$id.']field_value';
	$name = CHtml::resolveName($specificDatum,$name);
	
	echo Chtml::activeHiddenField($specificDatum, '['.$id.']field_name');
?>
<div class="simple">
<?php echo CHtml::label($p[$id], $name, array('id'=>$name)); ?>
<?php echo CHtml::activeTextField($specificDatum, '['.$id.']field_value') ?>
</div>

<?php 	
}
echo CHtml::activeHiddenField($project, 'id');
?>

<h2><?php echo Yii::t('project', 'Project detail'); ?></h2>
<?php echo CHtml::errorSummary($project); ?>


<div class="simple">
<?php
echo CHtml::activeLabelEx($project, 'activity');
echo CHtml::activeTextField($project, 'activity', array ('size' => 60, 'maxlength' => 255));
?>
</div>
<div class="simple">
<?php
echo CHtml::activeLabelEx($project, 'route_mnemonic');
echo CHtml::activeDropDownList($project, 'route_mnemonic', CHtml::listData(Route::model()->findAll('active=1'), 'mnemonic', 'label'), array (
	'style' => 'width:250px;'
));
?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($project,'description'); ?>
</div><br />
<?php
//echo CHtml::activeTextArea($project, 'description', array('rows' => '10', 'cols' => '80'));
$this->widget('application.extensions.ckeditor.CKEditorWidget',array(
	"model"=>$project,
	"attribute"=>'description',
	"ckEditor"=>Yii::app()->basePath."/../ckeditor/ckeditor.php",
    "ckBasePath"=>Yii::app()->baseUrl."/ckeditor/",
		"config" => array(
		"height"=>"400px",
		"width"=>"100%",
		"toolbar"=> Constants::ckEditorToolbars(),
	),
	"defaultValue" => $project->description,
));
?>


<div class="action">
<?php echo CHtml::submitButton(Yii::t('views', 'Save')); ?>
</div>

<?php echo CHtml::endForm(); ?>

</div><!-- yiiForm -->

<?php 

/*$this->widget('application.extensions.jwysiwyg.JWysiwyg', array (
	// required object CModel
	'model' => $project,
	// reqired attribute of model
	'attribute' => 'description',
	'width' => '80%',
	'height' => '400px',
	'right' => true
));*/

?>